evaluate right side first, then remember the result as the value on the left side
in case of fractions always round down


1) m.atk = primary stat + base power of spell + gear bonuses
	gear bonus:
		+3 weapon with "increases generic magic and damage item power"
		+3 armor with "increases generic magic and damage item power"
		+2 helm with "increases generic magic and damage item power"
		+1 Ancient Talisman
		+2 Crystal Ring
	base power:
		Lv1 spell: +25
			(-2 for each half level)
		Lv3 spell: +17
		boss spells may not hold to this rules


2) m.atk = m.atk * min(level + 38, 129)
this means level caps at 91 for spell damage purposes


3) m.atk = m.atk / 39


4) m.atk = m.atk + 1.5*level


5) m.atk = m.atk + secondary stat * (62 + level) / 53 + gear bonus
	gear bonus:
		Deathbringer weapon: +death penalty/4


6) if correct saber is present:
	m.atk = m.atk * 1.1


7) if spell has fire element and target leaf coat effect:
	m.atk = m.atk * 1.25
	remove leaf coat


8) m.atk = m.atk * character factor
	1.0 for player
	0.9~1.3 depending on enemy type


9) if Charlie with INT capstone on a light or dark damage spell
	m.atk = m.atk * 1.125 + 10


10) if Angela with STR capstone
	m.atk = max(0, p.atk - p.def) * 0.31 + m.atk


11) damage = max(10, m.atk - relevant defense)
	m.def in most cases
	p.def for Arrows, Darts, Jutsus, ...
	none for certain boss spells
	if Angela and INT capstone learned ignore up to 35 def


12) if Manslaughter (Rogue) equipped:
	if RNG[0..127] < LUCK+12:
		damage x1.5


13) if Maul of the Dead (Necromancer) equipped:
	damage = damage + (maxHP - HP)/4


14) for single target spells and always-MT spells:
	damage = damage * 1.25


15) magic attack up/down buff on caster
	damage = damage * 1.25 for buff
	damage = damage * 0.75 for debuff
	no change if both or neither


16) magic defense up/down buff on target
	damage = damage * 0.75 for buff
	damage = damage * 1.25 for debuff
	no change if both or neither


17) damage = damage * (3 + spell power factor + gear bonus)
	gear bonus:
		Skeleton Mail: +2 for Lv2.5 or lower
		Skeleton Mail: +1 for Lv3
	base power:
		Lv1 spell: +4
			(+1 for each half level)
		Lv3 spell: +8


18) damage = damage / 7


19) physical resistance/weakness
	only for "physical" spells like Shuriken
	x1.50 damage for weakness
	x0.50 damage for resistance
	x0.25 damage for strong resistance
	x0.00 damage for immunity


20) elemental resistance/weakness
	x1.50 damage for weakness
	x0.50 damage for resistance [skipped for Lv2 spells with Rune Staff equipped]
	x0.00 damage for immunity
	invert damage for absorption
	change target of damage in case of reflection
		if reflected AND the original target had Platinum Armor: x1.75 damage
		otherwise do not change damage


21) element of spell matches element of day (at least partially)
	damage x1.125


22) if caster is muted (e.g. for Magitech weapon)
	damage x0.5


24) difficulty factor
	varies by character and difficulty, compare to player/enemy strength in the README

24) damage degradation for targetting high level monster
	100% vs players
	100% vs enemies Lv1-10
	47.31% vs enemies Lv99


25) if spell dodge armor equipped
	if RNG[0..(evade/2+63)] > 50: damage / 2


26) boss gimmicks
	omitted because spoilers


27) cap at 999 damage